package com.mineplatform.web;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mineplatform.domain.M_Mine;
import com.mineplatform.domain.M_MineCategory;
import com.mineplatform.domain.M_Province;
import com.mineplatform.dto.BaseRep;
import com.mineplatform.dto.rep.ProvinceListRep;
import com.mineplatform.iservice.IM_AppInfoService;
import com.mineplatform.iservice.IM_MineCategoryService;
import com.mineplatform.iservice.IM_MineService;
import com.mineplatform.iservice.IM_ProvinceService;
import com.mineplatform.iservice.IM_ReplyService;
import com.mineplatform.iservice.IM_UserService;
import com.mineplatform.mapper.CategoryViewModelMapper;
import com.mineplatform.mapper.EditMineMapper;
import com.mineplatform.mapper.GetMinesViewModelMapper;
import com.mineplatform.mapper.ProvinceMapper;
import com.mineplatform.util.STATUSCODE;
import com.mineplatform.util.STATUSMSG;
import com.mineplatform.viewmodel.BaseResult;
import com.mineplatform.viewmodel.CategoryViewModel;
import com.mineplatform.viewmodel.CreateNewResult;
import com.mineplatform.viewmodel.EditMine;
import com.mineplatform.viewmodel.GetMinesViewModel;

@Controller
public class ApiController {

	private IM_ProvinceService _m_provinceservice;
	private IM_AppInfoService _m_appinfoservice;
	private IM_UserService _m_userservice;
	private IM_MineCategoryService _m_minecategoryservice;
	private IM_ReplyService _m_replyservice;
	private IM_MineService _m_mineservice;

	@Autowired
	public ApiController(IM_ProvinceService m_provinceservice, IM_AppInfoService m_appinfoservice,
			IM_UserService m_userservice, IM_MineCategoryService m_minecategoryservice, IM_ReplyService m_replyservice,
			IM_MineService m_mineservice) {
		this._m_provinceservice = m_provinceservice;
		this._m_appinfoservice = m_appinfoservice;
		this._m_userservice = m_userservice;
		this._m_minecategoryservice = m_minecategoryservice;
		this._m_replyservice = m_replyservice;
		this._m_mineservice = m_mineservice;
	}

	@RequestMapping(value = "/admin/api/category", method = RequestMethod.GET)
	public @ResponseBody List<CategoryViewModel> category() {
		List<M_MineCategory> list = this._m_minecategoryservice.find(null);
		return CategoryViewModelMapper.parse(list);
	}

	@RequestMapping(value = "/admin/api/getmines", method = RequestMethod.GET)
	public @ResponseBody List<GetMinesViewModel> getmines() {
		List<M_Mine> list = this._m_mineservice.find(null, null, null, null, null,null);
		return GetMinesViewModelMapper.parse(list);
	}

	@RequestMapping(value = "/admin/api/mine", method = RequestMethod.POST)
	public @ResponseBody BaseResult<?> createmine(@RequestBody EditMine data) {

		M_Mine mine = EditMineMapper.create(data);
		String id = this._m_mineservice.save(mine);

		CreateNewResult rep = new CreateNewResult();
		rep.setId(id);
		return new BaseResult<Object>(true, null, null, rep);
	}

	@RequestMapping(value = "/admin/api/mine", method = RequestMethod.PUT)
	public @ResponseBody List<GetMinesViewModel> updatemine() {
		List<M_Mine> list = this._m_mineservice.find(null, null, null, null, null,null);
		return GetMinesViewModelMapper.parse(list);
	}

	@RequestMapping(value = "/admin/api/mine", method = RequestMethod.DELETE)
	public @ResponseBody List<GetMinesViewModel> deletemine() {
		List<M_Mine> list = this._m_mineservice.find(null, null, null, null, null,null);
		return GetMinesViewModelMapper.parse(list);
	}

}
